package com.lecyon.farm.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lecyon.farm.base.BaseRequestPageVo;
import com.lecyon.farm.base.BaseRequestVo;
import com.lecyon.farm.base.BaseResponse;
import com.lecyon.farm.base.RestResponse;
import com.lecyon.farm.service.IObjectStoresConfigService;
import com.lecyon.farm.vo.add.AddObjectStoresConfigVo;
import com.lecyon.farm.vo.copy.DuplicateVo;
import com.lecyon.farm.vo.modify.ModifyObjectStoresConfigVo;
import com.lecyon.farm.vo.query.QueryObjectStoresConfigVo;
import com.lecyon.farm.vo.request.IdsVo;
import com.lecyon.farm.vo.view.ObjectStoresConfigVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 对象存储配置信息 前端控制器
 *
 * @author YaoZheng
 * @since 2020-04-20
 */
@RestController
@RequestMapping("/object-stores-config")
@Api(tags = "对象存储配置信息")
@ResponseBody
@CrossOrigin
public class ObjectStoresConfigController {

    private IObjectStoresConfigService objectStoresConfigService;

    @Autowired
    public ObjectStoresConfigController(IObjectStoresConfigService objectStoresConfigService) {
        this.objectStoresConfigService = objectStoresConfigService;
    }

    @ApiOperation(value = "新增同步条件设定", notes = "新增同步条件设定，author:YaoZheng")
    @PostMapping(value = "/post")
    public RestResponse<Long> add(@RequestBody @Valid AddObjectStoresConfigVo vo) {
        return objectStoresConfigService.add(vo);
    }

    @ApiOperation(value = "复制同步条件设定", notes = "复制同步条件设定，author:YaoZheng")
    @PostMapping(value = "/duplicate")
    public RestResponse<Long> duplicate(@RequestBody @Valid DuplicateVo vo) {
        return objectStoresConfigService.duplicate(vo);
    }

    @ApiOperation(value = "编辑同步条件设定", notes = "编辑同步条件设定，author:YaoZheng")
    @PostMapping(value = "/put")
    public RestResponse<Long> modify(@RequestBody @Valid ModifyObjectStoresConfigVo vo) {
        return objectStoresConfigService.modify(vo);
    }

    @ApiOperation(value = "删除同步条件设定", notes = "删除同步条件设定(支持批量删除)，author:YaoZheng")
    @PostMapping(value = "/remove")
    public BaseResponse remove(@RequestBody @Valid IdsVo vo) {
        return objectStoresConfigService.delete(vo);
    }

    @ApiOperation(value = "查看同步条件设定", notes = "查看同步条件设定，author:YaoZheng")
    @PostMapping(value = "/get")
    public RestResponse<ObjectStoresConfigVo> get(@RequestBody @Valid BaseRequestVo<QueryObjectStoresConfigVo> vo) {
        QueryObjectStoresConfigVo condition = vo.getEntity(QueryObjectStoresConfigVo.class);
        condition.setUserToken(vo.getUserToken());
        return objectStoresConfigService.get(condition);
    }

    @ApiOperation(value = "查询同步条件设定列表", notes = "查询同步条件设定列表(分页)，author:YaoZheng")
    @PostMapping(value = "/getList")
    public RestResponse<Page<ObjectStoresConfigVo>> getPageList(@RequestBody @Valid BaseRequestPageVo<QueryObjectStoresConfigVo> vo) {
        return objectStoresConfigService.getPageList(vo);
    }

    @ApiOperation(value = "查询同步条件设定下拉列表", notes = "查询同步条件设定列表(不分页)，author:YaoZheng")
    @PostMapping(value = "/getPullDownList")
    public RestResponse<List<ObjectStoresConfigVo>> getList(@RequestBody @Valid BaseRequestVo<QueryObjectStoresConfigVo> vo) {
        return objectStoresConfigService.getList(vo);
    }

    @ApiOperation(value = "导出查询同步条件设定列表", notes = "导出查询同步条件设定列表，author:YaoZheng")
    @PostMapping(value = "/exportList")
    public RestResponse<String> exportList(@RequestBody @Valid BaseRequestVo<QueryObjectStoresConfigVo> vo) {
        return objectStoresConfigService.exportExcel(vo);
    }

}
